<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>game2.css</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<link rel="stylesheet" href="../css/game2.css">
		<style>
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">扑克大抽奖</h1>
		</header>  
		<img src="../images/game2/bg.jpg" alt="" class="bgimg">
		<!--核心内容-->
		<div class="contentbox">
			<p class="time">正在竞猜<i id="countdown_time">44</i>秒</p>
			<div class="numbox">
				<p class="numboxtitle">投-得十</p>
				<div class="numboxcontent xiazhu">
					<button value="1"><img src="../images/game2/1.png"/><span class="chouma"></span></button>
					<button value="2"><img src="../images/game2/2.png"/><span class="chouma"></span></button>
					<button value="3"><img src="../images/game2/3.png"/><span class="chouma"></span></button>
					<button value="4"><img src="../images/game2/4.png"/><span class="chouma"></span></button>
					<button value="5"><img src="../images/game2/5.png"/><span class="chouma"></span></button>
					<button value="6"><img src="../images/game2/6.png"/><span class="chouma"></span></button>
					<button value="7"><img src="../images/game2/7.png"/><span class="chouma"></span></button>
					<button value="8"><img src="../images/game2/8.png"/><span class="chouma"></span></button>
					<button value="9"><img src="../images/game2/9.png"/><span class="chouma"></span></button>
					<button value="10"><img src="../images/game2/10.png"/><span class="chouma"></span></button>
					<button value="11"><img src="../images/game2/11.png"/><span class="chouma"></span></button>
					<button value="12"><img src="../images/game2/12.png"/><span class="chouma"></span></button>
					<button value="13"><img src="../images/game2/13.png"/><span class="chouma"></span></button>
					
				</div>
			</div>
			<div class="colorbox xiazhu">
				<p class="numboxtitle">投-得五</p>
				<div class="colorboxcontent">
					<button value="a"><img src="../images/game2/a.png"/><span class="chouma"></span></button>
					<button value="b"><img src="../images/game2/b.png"/><span class="chouma"></span></button>
					<button value="c"><img src="../images/game2/c.png"/><span class="chouma"></span></button>
					<button value="d"><img src="../images/game2/d.png"/><span class="chouma"></span></button>
				</div>
			</div>
			<div class="bigbox xiazhu">
				<p class="numboxtitle">投-得二</p>
				<div class="bigboxcontent">
					<button value="1"><img src="../images/game2/small.png"/><span class="chouma"></span></button>
					<button value="2"><img src="../images/game2/big.png"/><span class="chouma"></span></button>
				</div>
			</div>
			<div class="moneybox">
				<div class="moneyboxcontent">
					<button value="10" class="nomask"><span class="mask"></span><img src="../images/game2/m10.png"/></button>
					<button value="20"><span class="mask"></span><img src="../images/game2/m20.png"/></button>
					<button value="50"><span class="mask"></span><img src="../images/game2/m50.png"/></button>
					<button value="100"><span class="mask"></span><img src="../images/game2/m100.png"/></button>
				</div>
			</div>
			<div class="addbox">
				<span class="num">您的剩余果豆:<i id="guodou"></i></span>
				<a href="#"><img src="../images/game2/add.png" /></a>
			</div>
		</div>
		<div class="alertbox">
			<div class="outbox">
				<p>果豆不足,立即充值？</p>
			    <a class="noadd" href="JavaScript:void(0)">否</a>
			    <a class="yesadd" href="./add.html">是</a>
			</div>
			
		</div>
		
		
		<!--开奖动画--> 
		<div class="kaijiangbox">
			<div class="kaijiang">
			    <img id="img" class="xiaoming" src="../images/game2/back.png" alt="">
			    <img id="img" class="baby" src="../images/game2/back.png" alt="">
	        </div>
		</div>
		
		<script src="../js/mui.min.js"></script>
		<script src="../js/jquery.min.js"></script>
		<script type="text/javascript" src="../js/velocity.min.js"></script> 
		<script>   
		$(function() {
				 $.ajax({
			        type:"post",
			        url:"http://192.168.1.106/xlyx/puke/get_count_down.do",
			        async:true,
			        success: function(res){
			   
			       	 var sec = res.data;
			       	 
			       	 var c= function() {
			    		    sec--;
			    		   if (sec==10) {
                               stopmoney()
                               $(".xiazhu button").attr("disabled","true")
			    		   }   
			    		   if(sec==0){
			    			    get_lottery_result();//得到开奖结果  
			    			   setTimeout(function(){
			    			   	    sec=60;
			    			        window.location.reload();
			    			   },3500)
			    		   }
			    
			    		  document.getElementById("countdown_time").innerHTML = format(sec);
			    		}
			       	 var idt = window.setInterval(c, 1000);
			       	 var format = function(str) {
			       		    if(parseInt(str) < 10) {
			       		        return "0" + str;
			       		    }
			       		    return str;
			       		};
			        },
			        error: function(){
//			          alert("请刷新重试")
                   $(".kaijiangbox").show()
			          donghua()
			        }
			       
			   });
			   get_user_gold(); //我的金额  
			    
			   
			})
		// 停止下注
			function  stopmoney(){
			  // 数字和筹码
               var num=$(".numboxcontent button.haha").val();
               $(".numboxcontent button.haha").val()==undefined?num=0:num=num;
               var nummoney=$(".numboxcontent button.haha span img").attr("title");
               $(".numboxcontent button.haha span img").attr("title")==undefined?nummoney=0:nummoney=nummoney;
               console.log(nummoney)
              //花色和筹码 
               var color=$(".colorboxcontent button.haha").val();
               $(".colorboxcontent button.haha").val()==undefined?color=0:color=color;
               var colormoney=$(".colorboxcontent button.haha span img").attr("title");
               $(".colorboxcontent button.haha span img").attr("title")==undefined?colormoney=0:colormoney=colormoney;
               console.log(colormoney)
               console.log(color)
               // 大小和筹码
               var big=$(".bigboxcontent button.haha").val();
               $(".bigboxcontent button.haha").val()==undefined?big=0:big=big;
               var bigmoney=$(".bigboxcontent button.haha span img").attr("title");
               $(".bigboxcontent button.haha span img").attr("title")==undefined?bigmoney=0:bigmoney=bigmoney;
               console.log(bigmoney)
               console.log(big);
               var alldata=
                  {
                  	"num":num,
                  	"nummoney":nummoney,
                  
                  	"color":color,
                  	"colormoney":colormoney,
                  
                  	"big":big,
                  	"bigmoney":bigmoney,
                  };

                 $.ajax({
			         type:"post",
			         url:"http://192.168.1.106/xlyx/puke/puke_betting.do",
			         async:true,
			         data:alldata,
			         success: function(res){
			        	
			         },
			         error: function(){
			          
			         }
			    }); 
               
			}
		// 
			function get_lottery_result(){
				 $.ajax({
			         type:"post",
			         url:"http://192.168.1.106/xlyx/puke/get_lottery_result.do",
			         async:true,
			         success: function(res){
			        	 alert(res.data.pukeRes)
			        	 $(".kaijiangbox").show();
			        	 donghua("a13")
			         },
			         error: function(){
//			           alert("请刷新重试")
			         }
			    });
			}
// 获取余额
 get_user_gold()
			function get_user_gold(){
				 $.ajax({
			        type:"post",
			        url:"http://192.168.1.106/xlyx/puke/get_user_gold.do",
			        async:true,
			        success: function(res){
			       	$("#guodou").html(res.data);
			       	console.log($("#guodou").html())
			        },
			        error: function(){
//			          alert("请刷新重试")
			        }
			   });
			}	
	
        
			//开奖动画
			function donghua(num){
					 $(".kaijiang img").velocity({"rotateY":7200}
					      ,2800,"ease-in-out",function(){
					      	setTimeout(function (argument) {
					      		$(".baby").attr("src","../images/game2/"+num+".png")
					      	},200) 
					      $(".kaijiangbox").velocity({"scale":1},1500,function(){
					      	$(this).velocity({"scale":0},1000)
					      }) 
					    });	
					
			}
			//默认筹码
//			$(".xiazhu button .chouma").html($(".moneybox button.nomask").val())
			$(".moneyboxcontent button").click(function(){
				$(this).addClass("nomask").siblings().removeClass("nomask");
			})
			// 下注
			setTimeout(function(){
				
			var money=$(".addbox span i").html();
			console.log(money)
			$(".xiazhu button").click(function(){
				var allmoney=$(".addbox span i").html();
				if(allmoney>10){
					$(this).addClass("haha").siblings().attr("disabled",true)
					var num=parseInt($(".moneybox button.nomask").val());
				     $(this).find("span").show();  
				     $(this).find("span").html('<img title="'+num+'"'+'class="choumaimg" src="../images/game2/m'+num+'.png" />');
				     $(this).find("span").css({
				     	"top":Math.random()*60+"%",
				     	"left":Math.random()*60+"%",
				     });
				     var num1=$(".numboxcontent button.haha span img").attr("title");
				     var num2=$(".colorboxcontent button.haha span img").attr("title");
				     var num3=$(".bigboxcontent button.haha span img").attr("title");

				     isNaN(parseInt(num1)) ?num1=0:num1=parseInt(num1);
				     isNaN(parseInt(num2)) ?num2=0:num2=parseInt(num2);
				     isNaN(parseInt(num3)) ?num3=0:num3=parseInt(num3);
                     $(".addbox span i").html(money-num1-num2-num3)
                    
				}else{  
					$(".alertbox").show()
				}
			})
			},1)
			$(".alertbox .noadd").click(function(){
				$(".alertbox").hide()
			})
			
	
		</script>
	</body>

</html>